package test.匹配pmid图片相关;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import lombok.SneakyThrows;
import utils.SmallTool;
import utils.StringUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author: gcr
 * @Date: 2022-4-18 9:35
 */
public class 删除获取本地后空值fi3 {


    @SneakyThrows
    public static void main(String[] args) {
        // 获取老板的pmid 和figure 插入表

        // vm options -Xmx18660m -Xms12560m
        Db use = Db.use();

        String dbName = "pmiddoidown_gcr_local";


        int startPmid = 0;
        String allDate = "select max(pmid) as pmid  from " + dbName;
        Entity query = use.query(allDate).get(0);
        SmallTool.printMess("最大的id 是" + query.getStr("pmid"));

        Integer count = query.getInt("pmid");
        int breakSize = 100000;
        int pageSize = count / breakSize + 1;
        SmallTool.printMess("全部页码+++++++++" + pageSize);

        SmallTool.printMess("任务开始+++++++++++++++++++++++++++++++++++++++++++++++++++++");

        for (int i = 1; i <= pageSize; i++) {
            SmallTool.printMess("当前页码+++++" + i);
            int start = breakSize * (i - 1) + 1;
            int end = i * breakSize;
            SmallTool.printMess("开始id++" + start + "+++结束id++++" + end);
            if (end <= startPmid) {
                SmallTool.printMess("因为小于" + startPmid + " 略过了");
                continue;
            }
            String paramSql = "select pmid,figure from " + dbName + " where  pmid between  " + start + " and " + end;
            List<Entity> querys = use.query(paramSql);
            querys.parallelStream().forEach(entity -> {

                Integer pmid = entity.getInt("pmid");
                String figure = entity.getStr("figure");
                if (StringUtil.isNull(figure)) {
                    try {
                        Entity where = new Entity();
                        where.setTableName(dbName);
                        where.set("pmid", pmid);
                        use.del(where);
                    } catch (SQLException throwables) {
                        throwables.printStackTrace();
                    }

                }

            });
        }


    }


}
